package com.eb.controller;

import com.eb.context.BaseContext;
import com.eb.result.Result;
import com.eb.service.LikesService;
import com.eb.vo.LikeInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/likes")
@Api(tags = "点赞操作")
@Slf4j
@CrossOrigin//解决跨域问题
public class LikeController {
    @Autowired
    private LikesService likesService;

    /**
     * 点赞
     * @param innovationId
     * @return
     */
    @PostMapping("/addLike/{innovationId}")
    @ApiOperation("添加点赞")
    public Result<LikeInfoVO> addLike(@PathVariable Integer innovationId){
        log.info("对帖子{}点赞",innovationId);
        LikeInfoVO likeInfoVO = likesService.addLike(innovationId);
        return Result.success(likeInfoVO);
    }

    @PostMapping("/cancelLike/{innovationId}")
    @ApiOperation("取消点赞")
    public Result<LikeInfoVO> cancelLike(@PathVariable Integer innovationId){
        log.info("对帖子{}取消点赞",innovationId);
        return Result.success(likesService.deleteLike(innovationId));
    }
}
